package com.carl.zeus.server.system;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.carl.zeus.common.constant.BusinessCode;
import com.carl.zeus.common.constant.BusinessMsg;
import com.carl.zeus.common.util.BusinessMsgUtil;
import com.carl.zeus.dao.system.SysDepartmentMapper;
import com.carl.zeus.dao.system.SysRoleMapper;
import com.carl.zeus.model.system.SysDepartment;
import com.carl.zeus.model.system.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zcm
 * @since 2017-02-10
 */
@Service
public class SysDeptService extends ServiceImpl<SysDepartmentMapper, SysDepartment> {

    @Autowired
    private SysDepartmentMapper sysDepartmentMapper;

    public List<SysDepartment> listAjax(int page, int limit) {
        List<SysDepartment> roleList = sysDepartmentMapper.selectPage(
                new Page<SysDepartment>(page, limit),
                new EntityWrapper<>());
        return roleList;
    }

    public Integer countMenuList() {
        return sysDepartmentMapper.selectCount(new EntityWrapper<>());
    }

    public BusinessMsg updateDeptStatus(Long id) {
        sysDepartmentMapper.updateStatus(id, 0);
        return BusinessMsgUtil.returnCodeMessage(BusinessCode.GLOBAL_SUCCESS);
    }

    public BusinessMsg updateDeptBatchStatus(Long[] deptIds) {
        for (int i = 0; i < deptIds.length; i++) {
            updateDeptStatus(deptIds[i]);
        }
        return BusinessMsgUtil.returnCodeMessage(BusinessCode.GLOBAL_SUCCESS);
    }
}
